<template>
	<view>
		<block v-for="(item, index) in list" :key="item.id">
			<view @tap="jump(item)">
				<view class="post-item border-radius-lg">
					<block v-if="handle">
						<view v-if="item.status==1" class="post-item-status-label post-item-status-success-label">展示中</view>
						<view v-else-if="item.status==0" class="post-item-status-label post-item-status-warning-label">审核中</view>
						<view v-else-if="item.status==2" class="post-item-status-label post-item-status-warning-label">关闭中</view>
						<view v-else-if="item.status==-1" class="post-item-status-label post-item-status-error-label">审核失败</view>
					</block>
					<view class="post-item-top-user mb-20" v-if="isShowUser">
						<view class="mr-10" @click.stop="toUcenter(item.user.uuid)">
							<cos-avatar :src='item.user.avatar' :showSex="true" :sexIcon="item.user.gender_label"></cos-avatar>
						</view>
						<view class="center">
							<view class="d-flex align-items-center mb-5">
								<text class="username mr-10">{{ item.user.nickname.substring(0, 12) }}</text>
								<view class="tag-box d-flex" v-if="item.user.is_guaranty || item.user.is_cert">
									<view class="mr-10 tag tag-guaranty" v-if="item.user.is_guaranty==1"><u-icon name='rmb' color="#ffffff" size='23'></u-icon>已担保</view>
									<view class="mr-10 tag tag-cert" v-if="item.user.is_cert==1"><u-icon name='account-fill' color="#ffffff" size='23'></u-icon>已认证</view>
								</view>
							</view>
							<view class="d-flex align-items-center">
								<text class="sub-text font-size-base">
									<text class="mr-10" v-if="item.user.city || item.user.province">{{item.user.city || item.user.province}} |</text>
									<text class="mr-10">{{ item.user.identity_label}}</text>
								</text>
							</view>
						</view>
						<view class="right">
							<!-- <view class="address">
								<u-icon size="32" class="icon" name="map-fill"></u-icon>
								<text class="font-size-lg">全国</text>
							</view> -->
							<!-- <u-icon v-if="handle && sessionUid == uid" @tap.stop="onActive(item, index)" class="arrow-down" size="40" name="more-dot-fill"></u-icon>
							<u-icon v-else-if="admin" @tap.stop="onActive(item, index)" class="arrow-down" size="40" name="more-dot-fill"></u-icon>
							<u-icon v-else-if="sessionUid == item.uid" @tap.stop="onActive(item, index)" class="arrow-down" size="40" name="more-dot-fill"></u-icon> -->
							<!-- <view class="praise d-flex flex-column align-items-center text-color-assist">
								<u-icon name="thumb-up" size='40'></u-icon>
								<text>1500</text>
							</view> -->
							
							<u-icon v-if="admin" @tap.stop="onAuditing(item, index)" class="arrow-down" size="40" name="more-dot-fill"></u-icon>
						</view>
					</view>
					<view class="post-content">
						<rich-text class="post-text font-size-lg mb-20" :nodes="item.title"></rich-text>
						<view class="d-flex mb-20 align-items-center">
							<view style="width: 40rpx;">主图</view>
							<cos-post-image-style class="w-100" :images="item.master_images" ></cos-post-image-style>
						</view>
						<view class="d-flex mb-20 align-items-center mt-20" v-if="item.reference_images.length>0">
							<view style="width: 40rpx;">参考图</view>
							<cos-post-image-style class="w-100" :images="item.reference_images" :video="item.reference_video"></cos-post-image-style>
						</view>
					</view>
					<view class="text-color-danger mb-20" v-if="item.status==-1">驳回原因：{{item.reason}}</view>
					<!-- 底部 -->
					<view class="p-footer text-color-assist font-size-base justify-content-between align-items-center">
						<view class="">{{$f.timeAgo(item.time_diff)}}</view>
						<view class="d-flex">
							<!-- <text class="mr-20">阅读 1868</text>
							<text>点赞 77</text> -->
							<u-icon v-if="handle&&item.status!=0" name='setting' size="38" @tap.stop="onOperate(item, index)"></u-icon>
						</view>
					</view>
				</view>
			</view>
		</block>
		<!-- 操作弹窗 -->
		<u-action-sheet :list="operateList" v-model="operateAction" @click="operateActionCon"></u-action-sheet>
		<!-- 审核弹窗 -->
		<u-action-sheet :list="auditingList" v-model="auditingAction" @click="auditingActionCon"></u-action-sheet>
		<!-- 原因弹窗 -->
		<u-action-sheet :list="reasonList" v-model="reasonAction" @click="reasonActionCon"></u-action-sheet>
		<!-- 加载状态 -->
		<block v-if="list.length === 0 && loadStatus == 'nomore'">
			<u-empty margin-top="100" text="暂无作品" mode="favor"></u-empty>
		</block>
		<block v-else>
			<view style="margin: 30rpx 0;">
				<u-loadmore :status="loadStatus" />
			</view>
		</block>
	</view>
</template>

<script>
	export default {
		name: 'post-shoot-list',
		props: {
			list: Array,
			isShowUser:{
				type:Boolean,
				default:true
			},
			handle: {
				type: Boolean,
				default: false,
			},
			admin: {
				default: false,
				type: Boolean
			},
			loadStatus: String
		},
		data() {
			return {
				operateAction:false,
				operateList:[{
						text: '关闭',
						color: '',
						key: 'close',
						disabled: false
					},{
						text: '展现',
						color: 'green',
						key: 'open',
						disabled: false
					},{
						text: '删除',
						color: 'red',
						key: 'del',
						disabled: false
					}
				],
				auditingAction: false,
				reasonAction:false,
				auditingList: [{
						text: '通过',
						color: '',
						key: 'pass'
					},
					{
						text: '驳回',
						color: 'red',
						key: 'reject'
					}
				],
				reasonList:[{
						text: '图片带不明水印',
						color: '',
						key:1
					},{
						text: '不能出现任意联系方式',
						color: '',
						key:2
					},{
						text: '暴力，政治等',
						color: '',
						key:3
					},{
						text: '内容低俗',
						color: '',
						key:4
					},{
						text: '图片，文字涉黄',
						color: '',
						key:5
					}
				],
				choosePost: '',
				chooseIndex: '',
				sessionUid: ''
			};
		},
		methods: {
			onOperate(postInfo, index) {
				if(postInfo.status==1) {
					this.operateList[0].disabled = false;
					this.operateList[1].disabled = true;
				}else if(postInfo.status==2) {
					this.operateList[0].disabled = true;
					this.operateList[1].disabled = false;
				}else if(postInfo.status==-1) {
					this.operateList[0].disabled = true;
					this.operateList[1].disabled = true;
				}
				
				this.operateAction = true;
				this.choosePost = postInfo;
				this.chooseIndex = index;
			},
			operateActionCon(index) {
				let key = this.operateList[index].key;
				
				if (key == 'close') {
					this.close();
				}
				
				if (key == 'open') {
					this.open();
				}
				
				if(key == 'del') {
					let that = this;
					uni.showModal({
						title: '提示',
						content: '删除之后不可恢复，请谨慎操作！',
						confirmText:'确认删除',
						success (res) {
							if (res.confirm) {
								that.del();
							} 
						}
					})
				}
			},
			onAuditing(postInfo, index) {
				this.auditingAction = true;
				this.choosePost = postInfo;
				this.chooseIndex = index;
			},
			auditingActionCon(index) {
				let key = this.auditingList[index].key;
				if (key == 'pass') {
					this.pass();
				}

				if (key == 'reject') {
					this.reasonAction = true;
				}
			},
			reasonActionCon(index) {
				this.reject(this.reasonList[index].text);
			},
			pass() {
				uni.showLoading({
					mask: true,
					title: '通过中...'
				});
				
				this.$H.post('manager/pass', {id: this.choosePost.id, type:'task'}).then(res => {
					if (res.status === 200) {
						this.list.splice(this.chooseIndex, 1);
					}
					uni.hideLoading();
				});
			},
			reject(reason) {
				uni.showLoading({
					mask: true,
					title: '驳回中...'
				});
				
				this.$H.post('manager/reject', {id: this.choosePost.id, reason:reason, type:'task'}).then(res => {
					if (res.status === 200) {
						this.list.splice(this.chooseIndex, 1);
					}
					uni.hideLoading();
				});
			},		
			open(item, index) {
				uni.showLoading({
					mask: true,
					title: '展现中...'
				});
				
				this.$H.post('user/operate', {id: this.choosePost.id, status:1, type:'task'}).then(res => {
					if (res.status === 200) {
						this.list.splice(this.chooseIndex, 1);
					}
					uni.hideLoading();
				});
			},
			close() {
				uni.showLoading({
					mask: true,
					title: '关闭中...'
				});
				
				this.$H.post('user/operate', {id: this.choosePost.id, status:2, type:'task'}).then(res => {
					if (res.status === 200) {
						this.list.splice(this.chooseIndex, 1);
					}
					uni.hideLoading();
				});
			},
			del() {
				uni.showLoading({
					mask: true,
					title: '删除中...'
				});
				
				this.$H.post('user/del', {id: this.choosePost.id, type:'task'}).then(res => {
					if (res.status === 200) {
						this.list.splice(this.chooseIndex, 1);
					}
					uni.hideLoading();
				});
			},
			previewImage(url, urls) {
				let images = [];
				if(urls.length>0) {
					urls.forEach(item=>{
						images.push(item.url)
					})
				}
				
				uni.previewImage({
					current: url, // 当前显示图片的http链接
					urls: images // 需要预览的图片http链接列表
				});
			},
			previewMedia(media, images, video) {
				let medias = [];

				if(video.length>0) {
					medias.push({
						url:video[0].path,
						type:'video',
						poster:video[0].poster.path
					})
				}
				
				if(images) {
					images.forEach(item=>{
						medias.push({
							url:item.path,
							type:'image',
						})
					})
				}
				
				let current = 0;
				medias.forEach((item, index)=>{
					if(item.url==media) {
						current = index
					}
				})
				uni.previewMedia({
					sources: medias, // 需要预览的资源列表
					current: current // 当前显示的资源序号
				})
			},
			jump(item) {				
				uni.navigateTo({
					url: '/pages/notice/detail?id=' + item.id
				});
			},
			toUcenter(uuid) {
				uni.navigateTo({
					url: '/pages/user/home?uuid=' + uuid
				});
			}
		}
	};
</script>

<style lang="scss" scoped>
	.post-item {
		position: relative;
		background: #fff;
		padding: 25rpx 20rpx 20rpx 20rpx;
		margin-bottom: 20rpx;
		
		.post-item-status-label {
			position: absolute;
			right: 0;
			top: 0;
			color: #ffffff;
			padding: 0rpx 20rpx;
			border-bottom-left-radius: 20rpx;  /* 左下角 */
			border-top-right-radius: 20rpx;    /* 右上角 */
		}
		
		.post-item-status-success-label {
			background-color: $color-success;
		}
		.post-item-status-warning-label {
			background-color: $color-warning;
		}
		.post-item-status-error-label {
			background-color: $color-error;
		}

		.post-content {
			margin-top: 20rpx;
			
			.img-style-1 {
				display: block;
				width: 100%;
				max-height: 600rpx;
				border-radius: 10rpx;
				overflow: hidden;
			}

			.img-style-2 {
				display: flex;
				flex-wrap: wrap;
				
				image {
					margin: 5rpx;
					border-radius: 5px;
					width: 48.9%;
					height: 294rpx;
				}
			}

			.img-style-3 {
				position: relative;
				display: flex;
				flex-wrap: wrap;
				
				.icon {
					position: absolute;
					width: 60rpx;
					height: 60rpx;
					z-index: 999;
					top: 80rpx;
					left:90rpx;
				}

				.image {
					width: 31.3%;
					height: 200rpx;
					margin: 1%;
					border-radius: 10rpx;
				}
				
				.nums {
					position: absolute;
					right: 10rpx;
					bottom: 10rpx;
					background-color:rgba(0,0,0,0.4);
					color:#ffffff;
					padding:5rpx 15rpx;
					border-top-left-radius:10rpx;
				}
			}
		}

		.address {
			display: flex;
			font-size: 20rpx;
			border-radius: 20rpx;
			display: inline-block;
			padding: 0rpx 20rpx;

			.icon {
				margin-right: 5rpx;
			}
		}
	}

	.post-item-top-user {
		display: flex;
		align-items: center;
		
		.avatar {
			width: 90rpx;
			height: 90rpx;
			border-radius: 50%;
			margin-right: 10rpx;
			vertical-align: middle;
		}
		
		.center{
			flex: 1;
			display: flex;
			flex-direction: column;
			font-size: 24rpx;
			color: #999;
			.username{
				font-size: 30rpx;
				font-weight: 600;
				color: #616161;
			}
			
			.tag-box {
				.tag{
					padding: 0rpx 10rpx;
					border-radius: 5rpx;
					font-size: 24rpx;
					background-color: #f5f5f5;
					color: #616161;
				}
				
				.tag-guaranty {
					color: #ffffff;
					background-color: #24B19A;
				}
				
				.tag-cert {
					color: #ffffff;
					background-color: #5A84FB;
				}
			}
			 
			 
			
			.official{
				display: inline-block;
				font-size: 20rpx;
				color: #000;
				background-color: $themes-color;
				padding: 5rpx 10rpx;
				border-radius: 10rpx;
				margin-right: 10rpx;
			}
		}
		.right{
			height: 85rpx;
			.arrow-down{
				color: #999;
			}	
		}
	}

	.post-text {
		display: block;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 10;
		white-space: pre-wrap;
		overflow: hidden;
		font-size: 32rpx;
	}

	.discuss-title {
		height: 30rpx;
		padding: 10rpx;
		line-height: 30rpx;
		border-radius: 20rpx;
		font-size: 12px;
		background: #f0f0f5;
		color: #68c778;
		text-align: center;
	}

	.p-footer {
		display: flex;
		padding-top: 20rpx;
		border-top: 2rpx solid #F8F8F8;
		
		.p-item {
			margin: 0 auto;
			color: #616161;
			display: flex;
			align-items: center;

			.count {
				margin-left: 10rpx;
				font-size: 28rpx;
			}
		}

		.p-item[hidden] {
			display: none !important;
		}
	}

	.comment-wrap {
		font-size: 28rpx;
		padding-top: 20rpx;
		border-top: 1px solid #F5F5F5;
		.item{
			.name{
				color: #000;
				font-weight: 600;
			}
		}
	}

	.video-wrap {
		//display: flex;
		//justify-content: center;
		//align-items: center;
		//max-height: 500rpx;
		display: inline-block;
		height: 200rpx;
		
		.video-item {
			position: relative;
			
			.icon {
				width: 80rpx;
				height: 80rpx;
				z-index: 999;
				position: absolute;
				top: 0;left: 0;right: 0;bottom: 0;
				margin: auto;
			}
			
			.image {
				width: 31%;
				margin: 1%;
				border-radius: 10rpx;
			}
		}
	}
	
	.tags {
		display: flex;
	    position: relative;
	    font-size: 0;
	    font-family: Helvetica;
		flex-flow: wrap; 
		
		.tag {
		    position: relative;
		    display: inline-block;
			padding: 10rpx 40rpx;
		    color: #666;
		    font-size: 28rpx;
		    text-align: center;
		    border-radius: 60rpx;
		    background-color: rgb(239, 210, 52);
			margin-bottom: 20rpx;
			margin-right: 10rpx;
		}
	}
</style>
